<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Car_model extends CI_Model {

	function getFirstCar()
	{
		$this->db->order_by('car_id', 'desc');
		$this->db->limit(1);
		return $this->db->get('car');
	}

	function getAll($car_id,$type)
	{
		
		$this->db->where('car_id',$car_id);
		$this->db->where('type', $type);
		return $this->db->get('v_overview');
	}

	function getAllCustom()
	{
		return $this->db->get('v_custom');
	}

	function getCustomByID($id)
	{
		$this->db->where('id', $id);
		return $this->db->get('v_custom');
	}

	function getCustomByCar($car_id)
	{
		$this->db->where('car_id', $car_id);
		$this->db->where('status', '1');
		return $this->db->get('v_custom');
	}

	function getCarOverview($car_id,$type)
	{
		$this->db->where('car_id',$car_id);
		$this->db->where('type', $type);
		$this->db->order_by('order_num', 'asc');
		return $this->db->get('v_overview');
	}

	function getAllCar()
	{
		return $this->db->get('car');
	}

	function getAllCarGallery()
	{
		$this->db->select('id,image, series_name, cover_image');
		$this->db->join('car', 'car.car_id = car_gallery.car_id');
		$this->db->where('cover_image', '0');
		return $this->db->get('car_gallery');
	}

	function getGalleryByCar($car_id)
	{
		$this->db->select('id,image, series_name, cover_image');
		$this->db->join('car', 'car.car_id = car_gallery.car_id');
		$this->db->where('car_gallery.car_id', $car_id);
		return $this->db->get('car_gallery');
	}

	function getGalleryCover($car_id)
	{
		$this->db->where('cover_image', '1');
		$this->db->where('car_id', $car_id);
		return $this->db->get('car_gallery');
	}

	function getAllCarSpareparts()
	{
		return $this->db->get('v_spareparts');
	}

	function getAllCarBrochure()
	{
		return $this->db->get('v_brochure');
	}

	function getAllCarAccessories()
	{
		return $this->db->get('v_accessories');
	}

	function getSparepartsByCar($car_id)
	{
		$this->db->where('car_id', $car_id);
		return $this->db->get('v_spareparts');
	}

	function getBrochureByCar($car_id)
	{
		$this->db->where('car_id', $car_id);
		$this->db->order_by('id', 'desc');
		$this->db->limit(1);
		return $this->db->get('v_brochure');
	}

	function getAccessoriesByCar($car_id)
	{
		$this->db->where('car_id', $car_id);
		return $this->db->get('v_accessories');
	}

	
	function getCarSparepartsByID($id)
	{
		$this->db->where('id', $id);
		return $this->db->get('v_spareparts');
	}

	function getCarBrochureByID($id)
	{
		$this->db->where('id', $id);
		return $this->db->get('v_brochure');
	}

	function getCarAccessoriesByID($id)
	{
		$this->db->where('id', $id);
		return $this->db->get('v_accessories');
	}

	function getCarByID($id)
	{
		$this->db->where('car_id', $id);
		return $this->db->get('car');
	}

	function getOverviewPublish()
	{
		$this->db->distinct();
		$this->db->select("car.car_id,series_name,overview_status");
		$this->db->join('car', 'car.car_id = car_overview.car_id');
		return $this->db->get('car_overview');
	}

	function getOverviewByID($id)
	{
		$this->db->where('id', $id);
		return $this->db->get('car_overview');
	}

	function getCar()
	{
		return $this->db->get('car');
	}

	function updateOverview()
	{
		$object['overview_status'] = '0';
		$this->db->update('car', $object);
	}

	function updateCover()
	{
		$object['cover_image'] = '0';
		$this->db->update('car_gallery', $object);
	}

}

/* End of file car_model.php */
/* Location: ./application/models/car_model.php */